<?php
/**
 * FormStaticSelectionView
 *
 * @version    1.0
 * @package    samples
 * @subpackage tutor
 * @author     Pablo Dall'Oglio
 * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br)
 * @license    http://www.adianti.com.br/framework-license
 */
class FormStaticSelectionView extends TPage
{
    private $form;
    
    /**
     * Class constructor
     * Creates the page
     */
    function __construct()
    {
        parent::__construct();
        
        // create the notebook
        $notebook = new TNotebook(520, 160);
        
        // create the form
        $this->form = new TForm;
        
        // creates the notebook page
        $table = new TTable;
        
        // add the notebook inside the form
        $this->form->add($table);
        
        // adds the notebook page
        $notebook->appendPage('Static selection elements', $this->form);
        
        // create the form fields
        $radio = new TRadioGroup('radio');
        $check = new TCheckGroup('check');
        $combo = new TCombo('combo');
        
        $radio->setLayout('horizontal');
        $check->setLayout('horizontal');
        $combo->setSize(100);
        
        $items = array();
        $items['a'] ='Item a';
        $items['b'] ='Item b';
        $items['c'] ='Item c';
        
        $radio->addItems($items);
        $check->addItems($items);
        $combo->addItems($items);
        
        // add a row for one field
        $row=$table->addRow();
        $row->addCell(new TLabel('TRadioGroup:'));
        $cell = $row->addCell( $radio );
        
        // add a row for one field
        $row=$table->addRow();
        $row->addCell(new TLabel('TCheckGroup:'));
        $cell = $row->addCell( $check );
        
        // add a row for one field
        $row=$table->addRow();
        $row->addCell(new TLabel('TCombo:'));
        $cell = $row->addCell( $combo );
        
        // creates the action button
        $button1=new TButton('action1');
        // define the button action
        $button1->setAction(new TAction(array($this, 'onSave')), 'Save');
        $button1->setImage('ico_save.png');
        
        // add a row for the button
        $row=$table->addRow();
        $row->addCell($button1);
        
        // define wich are the form fields
        $this->form->setFields(array($radio, $check, $combo, $button1));
        
        // add the form inside the page
        parent::add($notebook);
    }
    
    /**
     * Simulates an save button
     * Show the form content
     */
    public function onSave($param)
    {
        $data = $this->form->getData(); // optional parameter: active record class
        
        // put the data back to the form
        $this->form->setData($data);
        
        // creates a string with the form element's values
        $message = 'Radio : ' . $data->radio . '<br>';
        $message.= 'Check : ' . print_r($data->check, TRUE) . '<br>';
        $message.= 'Combo : ' . $data->combo . '<br>';
        
        // show the message
        new TMessage('info', $message);
    }
}
?>